# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ast-grep
pkgver=0.28.1
pkgrel=0
pkgdesc="A CLI tool for code structural search, lint and rewriting"
url="https://github.com/ast-grep/ast-grep"
arch="all"
license="MIT"
makedepends="
	cargo
	cargo-auditable
	"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/ast-grep/ast-grep/archive/$pkgver/ast-grep-$pkgver.tar.gz
	remove-some-parsers.patch
	"

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --bin ast-grep --frozen --release

	local i; for i in bash fish zsh; do
		./target/release/ast-grep completions $i > target/$pkgname.$i
	done
}

check() {
	case "$CARCH" in
		x86_64) cargo test --frozen --workspace;;
		# Unit tests in ast_grep_dynamic are not multiplatform.
		*) cargo test --frozen --workspace --exclude ast-grep-dynamic;;
	esac
}

package() {
	install -D target/release/ast-grep -t "$pkgdir"/usr/bin/

	install -D -m644 target/$pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -D -m644 target/$pkgname.fish "$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -D -m644 target/$pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
988f57a1359342ab44bfd969892fd5bcea39edefe433a40bcd068ba24eac3a8c8c3c3fc1daf8636341e599888f28852d760b8a1cc0f5025ea8988117b78e8ddd  ast-grep-0.28.1.tar.gz
72c9652fce7389011977d9d3794ff463762f82079ea828f402f86fff7adce4fe1b8f8991f17dc3f98bfe3d51e1dc4599a3a7b87bbc10af89a5c11c61d1e83809  remove-some-parsers.patch
"
